/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon, Kinshuk Mishra
 												Neha Sugandh 
 												
Class							:				Metric Resources
 
Function						: 				Holding the metrics for resources. Used in 
												the distance calculation for CBR
****************************************************************************/
package cbr.metrics;

import base.WargusPlayer;
import base.WargusStateImporter;
import base.WargusUnit;

public class MetricResources {
	float m_gold = 0;
	float m_wood = 0;
	float m_oil = 0;
	float m_food = 0;
	float m_demand = 0;
	
	public void setGold(float val){m_gold = val;}
	public void setWood(float val){m_wood = val;}
	public void setOil(float val){m_oil = val;}
	public void setFood(float val){m_food = val;}
	public void setDemand(float val){m_demand = val;}
	
	public float getGold(){return m_gold;}
	public float getWood(){return m_wood;}
	public float getOil(){return m_oil;}
	public float getFood(){return m_food;} 
	public float getDemand(){return m_demand;} 
	
	public MetricResources() {
		m_gold = 0;
		m_wood = 0;
		m_oil = 0;
		m_demand = 0;
		m_food = 0; 
	}
	
	
	public MetricResources(WargusPlayer p) {
		int numFarms = 0;
		int numTownHalls = 0;
		m_gold = p.getGold();
		m_wood = p.getOil();
		m_oil = p.getWood();
		m_demand = 0;

		for(WargusUnit u : p.getUnits()) {
//			System.out.println("GetResourceMetrics: " + u.getType() + " (" + u.getCurrentHitPoints() + "/" + GameStateImporter.unitMaxHitPoints(u.getType()) + ")");
			
			// Status = 17 means "being-built"
			if(u.getType()==WargusStateImporter.unitTypeToInteger("pig-farm") && u.getStatus()[0]!=17) numFarms++;
			if(u.getType()==WargusStateImporter.unitTypeToInteger("farm") && u.getStatus()[0]!=17) numFarms++;
			if(u.getType()==WargusStateImporter.unitTypeToInteger("town-hall") && u.getStatus()[0]!=17) numTownHalls++;
			if(u.getType()==WargusStateImporter.unitTypeToInteger("great-hall") && u.getStatus()[0]!=17) numTownHalls++;
			if(u.getType()==WargusStateImporter.unitTypeToInteger("castle") && u.getStatus()[0]!=17) numTownHalls++;
			if(u.getType()==WargusStateImporter.unitTypeToInteger("keep") && u.getStatus()[0]!=17) numTownHalls++;
			if(u.getType()==WargusStateImporter.unitTypeToInteger("stronghold") && u.getStatus()[0]!=17) numTownHalls++;
			if(u.getType()==WargusStateImporter.unitTypeToInteger("fortress") && u.getStatus()[0]!=17) numTownHalls++;
		}
		m_food = 1+ numFarms*4 + numTownHalls; 
		for(WargusUnit u:p.getUnits()) {
			if (WargusStateImporter.unitSize(u.getType())==1) m_demand++;
		}
	}
	
	
	public MetricResources(WargusPlayer p,MetricResources m) {
		int numFarms = 0;
		int numTownHalls = 0;
		
		if (m!=null) {
			m_gold = m.m_gold;
			m_wood = m.m_wood;
			m_oil = m.m_oil;
			m_demand = m.m_demand;
			m_food = m.m_food;
		} else {
			m_gold = 0;
			m_wood = 0;
			m_oil = 0;
			m_demand = 0;
			m_food = 0;
		}

		m_gold += p.getGold();
		m_wood += p.getOil();
		m_oil += p.getWood();

		for(WargusUnit u : p.getUnits()) {
//			System.out.println("GetResourceMetrics: " + u.getType() + " (" + u.getCurrentHitPoints() + "/" + GameStateImporter.unitMaxHitPoints(u.getType()) + ")");
			
			// Status = 17 means "being-built"
			if(u.getType()==WargusStateImporter.unitTypeToInteger("pig-farm") && u.getStatus()[0]!=17) numFarms++;
			if(u.getType()==WargusStateImporter.unitTypeToInteger("farm") && u.getStatus()[0]!=17) numFarms++;
			if(u.getType()==WargusStateImporter.unitTypeToInteger("town-hall") && u.getStatus()[0]!=17) numTownHalls++;
			if(u.getType()==WargusStateImporter.unitTypeToInteger("great-hall") && u.getStatus()[0]!=17) numTownHalls++;
			if(u.getType()==WargusStateImporter.unitTypeToInteger("castle") && u.getStatus()[0]!=17) numTownHalls++;
			if(u.getType()==WargusStateImporter.unitTypeToInteger("keep") && u.getStatus()[0]!=17) numTownHalls++;
			if(u.getType()==WargusStateImporter.unitTypeToInteger("stronghold") && u.getStatus()[0]!=17) numTownHalls++;
			if(u.getType()==WargusStateImporter.unitTypeToInteger("fortress") && u.getStatus()[0]!=17) numTownHalls++;
		}
		m_food += 1+ numFarms*4 + numTownHalls; 
		for(WargusUnit u:p.getUnits()) {
			if (WargusStateImporter.unitSize(u.getType())==1) m_demand++;
		}
	}	
	

}
